//      sparse_vec.h
//      
//      SparseVector using non-zero indices
//      
//      Copyright 2012 tqlong <tqlong@espada>
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.

#ifndef __SPARSE_VEC_H
#define __SPARSE_VEC_H
#include "stl-helper.h"

class SparseVector : public std::vector<double>
{
  typedef std::vector<double> __BASE;
public:
  SparseVector() {}
  
  //double  operator [](int i) const;
  //double& operator [](int i) ;
  
  const SparseVector& t() const { return *this; }
  double value(int i) const { return this->at(i); }
  
  void zeros() { this->clear(); nz_.clear(); }
  
  const SparseVector& operator += (const SparseVector& x);
  const SparseVector& operator -= (const SparseVector& x);
  
public:
  vi_t nz_; // nonzero indices
};

std::ostream& operator << (std::ostream& os, const SparseVector& x);

SparseVector operator + (const SparseVector& x, const SparseVector& y);
SparseVector operator - (const SparseVector& x, const SparseVector& y);
SparseVector operator / (const SparseVector& x, double s);
SparseVector operator * (const SparseVector& x, double s);

namespace arma 
{
  double norm(const SparseVector& x, int type);
  double dot(const SparseVector& x, const SparseVector& y);
}

#endif
